package interview;

import java.util.Map;

public class Solution03 {
    public static void main(String[] args) {
        int[] nums = new int[]{1,8,6,2,5,4,8,3,7};
        System.out.println(getMax(nums));
    }
    public static int getMax(int[] nums) {
        int res = 0;
        int i = 0;
        int j = nums.length - 1;
        while (i < j) {
            res = Math.max(res, Math.min(nums[i], nums[j]) * (j - i));
            if (nums[i] > nums[j]) j--;
            else i++;
        }
        return res;
    }
}
